﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace cmdrunner
{
    internal class ProcessInfo
    {
        public ProcessInfo()
        {

        }

        public ProcessInfo(Process process)
        {
            this.Id = process.Id;
            this.Name = process.ProcessName;
        }

        public String Name;
        public int Id;
        public int ParentId;
        public List<ProcessInfo> Children;

        /// <summary>
        ///  关闭本线程
        /// </summary>
        public void Terminate()
        {
            Process process = Process.GetProcessById(Id);
            if (process != null)
            {
                process.Kill();
            }
        }

        /// <summary>
        /// 关闭所有子孙线程，然后关闭自身
        /// </summary>
        public void TerminateAfterChildren()
        {
            foreach (ProcessInfo child in Children)
            {
                child.TerminateAfterChildren();
            }
            Terminate();
        }
    }
}

